package com.ctsi.ssdc.controller;

import com.ctsi.ssdc.entity.Excel02;
import com.ctsi.ssdc.service.Excel02Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 2分区镇一般公共预算收入(Excel02)表控制层
 *
 * @author makejava
 * @since 2023-02-20 13:03:31
 */
@RestController
@RequestMapping("excel/02")
public class Excel02Controller {
    /**
     * 服务对象
     */
    @Resource
    private Excel02Service excel02Service;

    /**
     * 分页查询
     *
     * @param excel02     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Excel02>> queryByPage(Excel02 excel02,@PageableDefault Pageable pageRequest) {
        return ResponseEntity.ok(this.excel02Service.queryByPage(excel02==null?new Excel02():excel02, (PageRequest) pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Excel02> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.excel02Service.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param excel02 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Excel02> add(Excel02 excel02) {
        return ResponseEntity.ok(this.excel02Service.insert(excel02));
    }

    /**
     * 编辑数据
     *
     * @param excel02 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Excel02> edit(Excel02 excel02) {
        return ResponseEntity.ok(this.excel02Service.update(excel02));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.excel02Service.deleteById(id));
    }

}

